package ac.manchester.cs.afzal.autoservd.Descriptors;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
 * AutoServD : Automatic Service Descriptions of Bioinformatics Web Services
 * @author hamafz
 */
public class Descriptors_Main
{
    private Properties props;
    static private SQL_Handler_Descriptors sqlHandler;
    

    /**
     * Default Constructor
     */
    public Descriptors_Main()
    {
        try
        {
            sqlHandler = new SQL_Handler_Descriptors();
            sqlHandler.initialize_parameters("jdbc:mysql://localhost:3306/BMC_2009_2", "root", "admin");
            sqlHandler.connect_db();
            props = new Properties();
            props.load(new FileInputStream("AutoServD.properties"));
        }
        catch (IOException ex)
        {
            Logger.getLogger(Descriptors_Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     *
     * @param args
     */
    public static void main(String[] args)
    {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String input;
        try
        {
            System.out.println(
                    "*****************************************************");
            System.out.print(
                    "Please Choose among following options: \n" +
                    " 1. Extract Service Descriptions from text files \n" +
                    " 1a. Extract Top 300 terms from Results_Final \n" +
                    " 2. Extract Descriptors from temp table and export in __bioinformatics_service_descriptors \n" +
                    " 3. Export __bioinformatics_service_descriptors to XML \n" +
                    " 4. Convert Service Descriptors to Ngrams \n" +
                    " 5. Convert Sentence Descriptors to Ngrams \n" +
                    " Enter number to continue or 'e' to exit : ");
            input = in.readLine();
            input = input.trim();

            if (input.equals("1"))
            {
                Descriptor_Processor extract_descriptor = new Descriptor_Processor();
                extract_descriptor.extract_nps_from_text_files();
            }
            else if (input.equals("1a"))
            {
                Descriptor_Processor extract_descriptor = new Descriptor_Processor();
                extract_descriptor.extract_top_300_terms();
            }

            else if (input.equals("2"))
            {
                Descriptor_Processor extract_descriptor = new Descriptor_Processor();
                extract_descriptor.export_descriptors_to_bioinformatics_service_descriptors_table();
            }
            else if (input.equals("3"))
            {
                Descriptor_Processor extract_descriptor = new Descriptor_Processor();
                extract_descriptor.export_to_xml();
            }
            else if (input.equals("4"))
            {
                Descriptors_Ngrams extract_descriptor = new Descriptors_Ngrams();
                extract_descriptor.make_ngrams_service_descriptors();
            }
            else if (input.equals("5"))
            {
                Descriptors_Ngrams extract_descriptor = new Descriptors_Ngrams();
                extract_descriptor.make_ngrams_sentence_descriptors();
            }
            else if (input.equals("e"))
            {
                System.exit(0);
            }
        }
        catch (Exception ex)
        {
            System.out.println(
                    "Value of Exception in reading input is : " + ex.getMessage());
        }
    }
}
